package aos.ydksxt.service.xxdjgl;

import aos.framework.core.typewrap.Dto;
import aos.framework.core.typewrap.Dtos;
import aos.framework.core.utils.AOSJson;
import aos.framework.core.utils.AOSUtils;
import aos.framework.web.router.HttpModel;
import aos.ydksxt.dao.DjFcsyqdjxx;
import aos.ydksxt.service.common.CommonService;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 房产租赁信息管理服务
 * Created by Stiofan on 2017/1/19.
 */
@Service
public class FcczxxglService extends CommonService {

    @Override
    @Transactional
    public void initView(HttpModel httpModel) {
        httpModel.setViewPath("/ydksxt/xxdjgl/fcczxxgl.jsp");
    }
    @Transactional
    public void queryFcczxxByFcbh(HttpModel httpModel) {
        Dto inDto = httpModel.getInDto();
        Dto params = Dtos.newDto("fcbh", inDto.get("fcbh"));
        List fccxxxs = persistenceDAO.findAllBySql("select nvl(kz.shxydm, xx.nsrsbh) nsrsbh,\n" +
                "       xx.nsrmc,\n" +
                "       syq.*,\n" +
                "       syq.fcsyq_ysmj * syq.fcsyq_ysje * 12 fcsyq_zlje\n" +
                "  from ydks.dj_fcsyqdjxx syq, ydks.dj_ryxx xx, ydks.dj_ryxx_kz kz\n" +
                " where syq.djxh = xx.djxh\n" +
                "   and xx.djxh = kz.djxh\n" +
                "   and syq.yxbz = 'Y'\n" +
                "   and syq.fcsyrlx_dm != '01'\n" +
                "   and syq.fcsyqlx_dm = '02'\n" +
                "   and xx.yxbz = 'Y'\n" +
                "   and kz.yxbz = 'Y'\n" +
                "   and syq.fcbh = :fcbh", params);
        httpModel.setOutMsg(AOSJson.toJson(AOSUtils.object2Map(fccxxxs)));
    }
    @Transactional
    public void zfFcsyqdjxxByFcsyquuid(HttpModel httpModel) {
        Dto inDto = httpModel.getInDto();
        Dto params = Dtos.newDto("fcsyquuid", inDto.get("fcsyquuid"));
        DjFcsyqdjxx djFcsyqdjxx = (DjFcsyqdjxx) persistenceDAO.findSingleByHql("from DjFcsyqdjxx xx where xx.fcsyquuid=:fcsyquuid", params);
        djFcsyqdjxx.setZfrq(getDateTime());
        djFcsyqdjxx.setZfrDm(getCzryDm(httpModel));
        djFcsyqdjxx.setZfyy(inDto.getString("zfyy"));
        djFcsyqdjxx.setYxbz("N");
        djFcsyqdjxx.setXgrDm(getCzryDm(httpModel));
        djFcsyqdjxx.setXgrq(getDateTime());
        Dto outDto = Dtos.newOutDto();
        try {
            persistenceDAO.saveOrUpdate(djFcsyqdjxx);
            outDto.setAppCode("suc");
        } catch (Exception e) {
            outDto.setAppCode("err");
            outDto.setAppMsg(e.getMessage());
        }
        httpModel.setOutMsg(AOSJson.toJson(outDto));
    }
}
